# -*- coding: utf-8 -*-
from scpy.logger import get_logger
import os
import sys
import json
from pgutil import *

reload(sys)
sys.setdefaultencoding('utf-8')

logger = get_logger(__file__)

CURRENT_PATH = os.path.dirname(__file__)
if CURRENT_PATH:
    CURRENT_PATH = CURRENT_PATH + "/"

pg = PgUtil()

def main():
    with open('schoolDict.json','r') as f:
        text = f.read()
        school_list = json.loads(text)
        for school_item in school_list:
            _sql = """
                    insert into collage(
                    name,
                    old_name,
                    province,
                    rank,
                    property,
                    type,
                    nature,
                    url,
                    degree_level,
                    f211,
                    f985
                    ) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
                   """
            _values = [
                school_item['schoolname'],
                school_item['oldname'],
                school_item['province'],
                int(school_item['ranking']),
                school_item['schoolproperty'],
                school_item['schooltype'],
                school_item['schoolnature'],
                school_item['guanwang'],
                school_item['level'],
                int(school_item['f211']),
                int(school_item['f985']),
            ]
            try:
                pg.execute_insert_sql(_sql,_values)
                logger.info('insert collage info success')
            except Exception,e:
                logger.error('insert collage info failed for %s'%str(e))

if __name__ == '__main__':
    main()